package com.djsearch.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.djsearch.R;
import com.djsearch.bean.GroupBuyGoods;
import com.djsearch.bean.PlaneTicket;

public class JiPiaoListViewAdapter extends BaseAdapter{

	private Context mContext;
	private List<PlaneTicket> jipiaoList;
	
	public JiPiaoListViewAdapter(Context context,List<PlaneTicket> jipiaoList) {
		mContext = context;
		this.jipiaoList = jipiaoList;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return jipiaoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return jipiaoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void refreshData(List<PlaneTicket> list) {
		jipiaoList = list;
		notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		if (convertView == null) {
			LayoutInflater layoutInflater = ((Activity) mContext).getLayoutInflater();
			convertView = layoutInflater.inflate(R.layout.jipiao_listview_item, parent, false);
			convertView.setTag(convertView);
		} else {
			convertView = (View) convertView.getTag();
		}
		//航空公司名字
		TextView gongsiName = (TextView)convertView.findViewById(R.id.gongsiName);
		gongsiName.setText(jipiaoList.get(position).getAirlineDibitCode());
		//机型
		TextView flightType = (TextView)convertView.findViewById(R.id.planType);
		flightType.setText(" ( " + "机型:" + jipiaoList.get(position).getFlight() + " )");
		//起飞时间
		TextView startTime = (TextView)convertView.findViewById(R.id.startTime);
		startTime.setText(jipiaoList.get(position).getStartTime());
		//起飞地点
		TextView startPlace = (TextView)convertView.findViewById(R.id.startPlace);
		startPlace.setText(jipiaoList.get(position).getDepartAirportCode());
		//到达时间
		TextView arriveTime = (TextView)convertView.findViewById(R.id.arriveTime);
		arriveTime.setText(jipiaoList.get(position).getEndTime());
		//到达地点
		TextView arrivePlace = (TextView)convertView.findViewById(R.id.arrivePlace);
		arrivePlace.setText(jipiaoList.get(position).getArriveAirportCode());
		//机票价格
		TextView price = (TextView)convertView.findViewById(R.id.price);
		price.setText(jipiaoList.get(position).getPrice());
//		//价格折扣
//		TextView sale = (TextView)convertView.findViewById(R.id.sale);
//		sale.setText("( " + jipiaoList.get(position).getSale() + "折 )");
		return convertView;
	}







}
